// var baseUrl = 'http://192.168.0.158:8086';
// var pirUrl = 'http://61.144.241.236:10089/'; // 图片路径

$(document).ready(function(){   
  console.log(baseUrl)
  getAllCategory();
  getBannerImg();
  getShopDetail();
});


// 获取首页导航栏信息
function getAllCategory(){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/category/selectTSystemCategoryVo",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var data={
          data:res.data,
        };
        var html = template('stab-script', data);
        document.getElementById('stab-box').innerHTML = html;
        var html2 = template('StabC-script', data);
        document.getElementById('StabC').innerHTML = html2;
      }
    },
    error:function(res){
          
    },
  })
};

// 获取首页轮播图
function getBannerImg(){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/homeBanner/getHomeBannerPc",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var data={
          data:res.data,
          pirUrl:pirUrl
        };
        var html = template('swiper-wrapper-script', data);
        document.getElementById('swiper-wrapper').innerHTML = html;
        var mySwiper = new Swiper('.swiper-container', {
          swipeToNext: true,
          pagination : '.pagination',
          paginationClickable: true,
          autoplay: 5000, //可选选项，自动滑动
          loop: true, //可选选项，开启循环
        });
        
        $('#prve').click(function(){
          mySwiper.swipePrev();
        })
        $('#next').click(function(){
          mySwiper.swipeNext();
        })
      }
    },
    error:function(res){
          
    },
  })
};

// 获取店铺数据
function getShopDetail(){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/solr/selectShopByKeyWordsPc",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var tempData = res.data;
        for(var i = 0 ; i < tempData.length ; i ++){
          for(var j = 0 ; j < tempData[i].list.length ; j ++){
            tempData[i].list[j].round =  Math.round(tempData[i].list[j].shopEvaluateValue);
            tempData[i].list[j].cha = 5-tempData[i].list[j].round;
          }
        }
        var data={
          data:tempData,
          pirUrl:pirUrl
        };
        var html = template('goods-detail-script', data);
        document.getElementById('shop-detail-box').innerHTML = html;
      }
    },
    error:function(res){
          
    },
  })
}

